<!--
  审核商品入库组件:商品入库的信息会在这里显示 批准和不批准
-->
<script>
export default {
  name: "BuyCheck",
  data() {
    return {
      userId: 0,
      dialogFormTitle: '',

      tiJiaoInfo: {
        goodsId: 0,
        allCount: 0,

        loginInfoId: 0,
        checkUserId: 0,
        status: 0,
        info: '',
      },

      tableData: [],
      allGoodsType: [],
      dialogFormVisible: false,
      formLabelWidth: '140px',
    };
  },
  methods: {

    // 查询所有申请入库商品
    findData() {
      this.$http.get("/goods/findGoodsLoginInfo")
          .then((res) => {
            console.log("所有入库请求")
            console.info(res)
            res.data.forEach(item => {
              if (item.info === null) item.info = "(无)"
              item.goodsPicture = "http://localhost:2001/picture/" + item.goodsPicture + ".jpg";
            });
            this.tableData = res.data;
          });
    },
// 允许
    yunXu(row) {
      console.log("row")
      console.info(row)
      // 该消息的状态改为1
      this.tiJiaoInfo.allCount = row.thisGoodsCount + row.buyCount;
      this.tiJiaoInfo.goodsId = row.goodsId
      this.tiJiaoInfo.loginInfoId = row.id
      this.tiJiaoInfo.checkUserId = this.userId
      this.tiJiaoInfo.status = 1
      this.dialogFormVisible = true

    },
    // 拒绝
    juJue(row) {
      this.tiJiaoInfo.allCount = row.thisGoodsCount
      this.tiJiaoInfo.goodsId = row.goodsId
      this.tiJiaoInfo.loginInfoId = row.id
      this.tiJiaoInfo.checkUserId = this.userId
      this.tiJiaoInfo.status = 2
      this.dialogFormVisible = true
      // 该消息的状态改为2 并填写理由
    },
    queDing() {
      console.log("提交前的最后数据")
      console.info(this.tiJiaoInfo)
      this.$http.post('/goods/updateStatusById', this.tiJiaoInfo)
          .then(res => {
            if (res.data.msg === 1) {
              this.$message.success("操作完成")
              this.findData()
            } else {
              this.$message.error("入库失败")
            }
          })
      this.tiJiaoInfo = {}
      this.dialogFormVisible = false
    }
  },
  created() {
    let user_info = sessionStorage.getItem("session_user");
    if (user_info) this.userId = JSON.parse(user_info).id;

    this.findData();
    console.log('GoodsAdmin准备完成');
  }
};

</script>

<template>
  <div>

    <el-dialog title="提示" :visible.sync="dialogFormVisible" width="50%">
      <el-form :model="tiJiaoInfo" label-width="100px" class="demo-ruleForm">
        <el-form-item label="补充信息">
          <el-input type="textarea" v-model="tiJiaoInfo.info"/>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="queDing()">确 定</el-button>
  </span>
    </el-dialog>

    <el-table :data="tableData" style="width: 100%">

      <el-table-column label="名称" prop="goodsName" width="80"/>
      <el-table-column label="图片" width="150" align="center">
        <template #default="scope">
          <el-image style="width: 50px; height: 50px" :src="scope.row.goodsPicture" fit="cover"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="商品现有库存" prop="thisGoodsCount"/>
      <el-table-column label="入库商品数量" prop="buyCount"/>
      <el-table-column label="入库商品单价" prop="oneMoney"/>
      <el-table-column label="所需总金额" prop="allMoney"/>
      <el-table-column label="信息" prop="info"/>
      <el-table-column label="审批">
        <template #default="scope">
          <div v-if="scope.row.status === 0">
            <el-button @click="yunXu(scope.row)">允许</el-button>
            <el-button @click="juJue(scope.row)">拒绝</el-button>
          </div>
          <div v-else-if="scope.row.status === 1">已批准</div>
          <div v-else-if="scope.row.status === 2">已拒绝</div>

        </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<style scoped>

</style>